package org.es.sql.utils;

import org.elasticsearch.common.bytes.BytesReference;
import org.elasticsearch.common.io.stream.BytesStream;
import org.elasticsearch.common.xcontent.XContentBuilder;

import java.io.OutputStream;

/**
 * @author Zhouwx
 * @version 1.0
 * @date 2024/2/5 15:23:54
 * @description
 */
public class XContentBuilderUtil {

    public static String string(XContentBuilder xContentBuilder) {
        OutputStream outputStream = xContentBuilder.getOutputStream();
        xContentBuilder.close();
        BytesReference bytesReference = ((BytesStream) outputStream).bytes();
        String string = bytesReference.utf8ToString();
        return string;
    }

}
